package com.asia5b.a5mall.member.adapter

import androidx.core.content.ContextCompat
import android.widget.TextView
import com.asia5b.a5mall.member.R
import com.asia5b.a5mall.middleware.model.member.RegionModel
import com.asia5b.a5mall.middleware.model.bean.TabRegionBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.jakewharton.rxbinding3.view.clicks
import java.util.concurrent.TimeUnit

/**
 * Created by zhangyuncai on 2020/5/7.
 */
class RegionContentChildAdapter(var tabRegionBean: TabRegionBean, var callback: (selectRegionModel: RegionModel) -> Unit):
BaseQuickAdapter<RegionModel,BaseViewHolder>(R.layout.item_region_contentchild_adapter,tabRegionBean.contentRegionModelList!!){
    override fun convert(helper: BaseViewHolder, item: RegionModel) {
        val tv_region_content_name = helper.getView<TextView>(R.id.tv_region_contentchild_name)
        tv_region_content_name.text = item.name
        if (tabRegionBean.selectRegionModel?.id?:0 == item.id) {
            tv_region_content_name.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryDark))
        } else {
            tv_region_content_name.setTextColor(ContextCompat.getColor(context, R.color.common_text_black))
        }

        helper.itemView.clicks()
                .throttleFirst(1, TimeUnit.SECONDS)
                .subscribe {
                    callback.invoke(item)
                }
    }
}